import random
from typing import Callable, List

from starlette.middleware.base import BaseHTTPMiddleware
from starlette.requests import Request
from starlette.responses import Response


class AuthMiddleware(BaseHTTPMiddleware):
    white_list: List[str] = ["/docs", "/favicon.ico", "/openapi.json", "/nacos/health"]

    async def dispatch(self, request: Request, call_next: Callable) -> Response:
        # request_url = request.url.path
        # for item in self.white_list:
        #     if request_url.startswith(item):
        #         return await call_next(request)
        #
        # token = request.headers.get("Token")
        #
        # if not token:
        #     return Response("Unauthorized", status_code=401)

        return await call_next(request)
